package me.chenzhijun.eurekaclient.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class WebController {

    @Autowired
    private DiscoveryClient client;

    @GetMapping(value = "/index")
    public String index() {
        List<String> services = client.getServices();
        services.forEach(str -> {
            List<ServiceInstance> instances = client.getInstances(str);
            instances.forEach(obj -> {
                System.out.println(str + " : " + obj.getHost() + ":" + obj.getPort() + "/" + obj.getUri() + "/" + obj.getServiceId() + "/" + obj.getMetadata());
            });
        });
        return "hello,World";
    }
}
